<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
defined('BASEPATH') || exit('No direct script access allowed');
$this->load->helper('url');
?>
	<table id="tt" class="easyui-datagrid"></table>
	
	
	<div id="tb" style="padding:10px;5px;height:auto">
		<div style="margin-top:10px">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="add">添加</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true" id="del">删除</a>
		</div>
	</div>
	<div id="win"></div>

<script language="javascript">

$(function(){
	$('#tt').datagrid({
		url:'<?php echo site_url('slide/data');?>',
		pagination:true,
		pageSize:20,
		toolbar:'#tb',
		checkbox:true,
		fit:true,
		fitColumns:true,
		border:false,
		idField:'id',
		nowrap:true,
		autoRowHeight:true,
		'columns':[[
			{field:'ck',checkbox:'true'},
			{field:'id',width:'9%',title:'编号'},
			{field:'img',width:'35%',title:'图片',formatter:function(value,row,index){return '<img src="/upload/slide/'+row.img+'" width=100% height=100>';}},
			{field:'url',width:'15%',title:'链接地址'},
			{field:'sort',width:'15%',title:'排序'},
			{field:'status',width:'15%',title:'是否显示',formatter:function(value,row,index){if(row.status==0)return '否';else return '是';}},
			{field:'action',width:'10%',title:'操作',formatter:function(value,row,index){return '<a href="javascript:doedit('+row.id+')" iconCls="icon-edit" class="list_link easyui-linkbutton">修改</a>';}}
		]],
		onLoadSuccess:function(data){$(".list_link").linkbutton()}
	});
	
	$('#add').click(function(){
		$('#win').window('open');
		$('#win').window('refresh', '<?php echo site_url('slide/add');?>');
	});

	$('#win').window({
		width:450,
		height:500,
		modal:true,
		closed:true,
		title:'添加/修改'
	});

	$('#del').click(function(){
		var rows = $('#tt').datagrid('getChecked');
		if(rows.length == 0){  
			$.messager.alert('Info','请至少选择一行数据！','info');
			return false;  
		}

		var ids = [];
		$.each(rows,function(index,item){
			ids.push(item.id);
		});
		
		$.messager.confirm('确认信息','您确定要删除吗？删除之后不能恢复',function(r){
			if(r){
				$.getJSON('<?php echo site_url('slide/del');?>',{'id[]':ids},function(d){
					$.messager.alert('信息提示',d.msg,'info');
					
					if(d.error == 0){
						$('#tt').datagrid('reload');
					}
				});
			}
		});
		
	});
});
function doSearch(){
	$('#tt').datagrid('load',{
		id: $('#id').val(),
		name: $('#name').val(),
		status: $('#status').val()
	});
}
function doedit(id){
	$('#win').window('open');
	$('#win').window('refresh', '<?php echo site_url('slide/edit/\'+id+\'');?>');
}

</script>